let id = 0

class Dep {
  constructor() {
    this.id = id++
    // 存放watcher
    this.subs = []
  }
  depend() {
    // watcher进行依赖收集，同时dep也对watcher进行收集
    Dep.target.addDep(this)
  }
  addSub(watcher) {
    this.subs.push(watcher)
  }
  notify() {
    this.subs.forEach(watch => {
      watch.update()
    })
  }
}

// 静态变量，存储最近的watcher
Dep.target = null

export default Dep